<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <title>Examples</title>
    <meta name="keywords" content="">
    <link href="" rel="stylesheet">

    <script type="text/javascript" src="lib/vue.js"></script>
</head>

<body>
    <div id="box">
        <input type="text" v-model="userInput" />
        <!-- <input type="text" @input="handleInput" /> -->

        <ul>
            <li v-for="data in computedList">
                {{data}}
            </li>
        </ul>
    </div>

    <script>
        new Vue({
            el: "#box",
            data: {
                cartList: ["abc", "bcd", "def", "fgh"],
                list: ["abc", "bcd", "def", "fgh"],
                userInput:""
            },
            watch: {
                userInput() {
                    console.log("userInput发生变化");
                    this.cartList = this.list.filter(value => value.indexOf(this.userInput) > -1)
                }
            },
            computed:{
                computedList(){
                    return this.list.filter(value => value.indexOf(this.userInput) > -1)
                }
            }
        })
    </script>

</body>

</html>